#include "gameseleced.h"
#include<QIcon>
#include<QPaintEvent>
#include<QPainter>
#include<QPushButton>
#include"widget.h"
#include<QSound>
#include"gameroom.h"
#include<QTextStream>
#include<QTextEdit>
gameSeleced::gameSeleced(QWidget *parent) : QWidget(parent)
{
//设置图标和标题

    this->setWindowTitle("关卡选择");
    this->setWindowIcon(QIcon(":/icon.png"));

    QPushButton* backButton=new QPushButton(this);
    backButton->move(900,750);
    backButton->setIcon(QIcon(":/back.png"));
    connect(backButton,&QPushButton::clicked,[=](){
        Widget* widget=new Widget;
        this->close();
        widget->show();
        QSound::play(":/clicked.wav");

    });

       gameroom* gameRoom=new  gameroom;

//设置四个按钮 简单模式 一般模式 困难模式  历史战绩
     QPushButton* simpleButton=new QPushButton(this);
         simpleButton->move(440,250);
         simpleButton->setText("简单模式");
         QFont font("华文行楷",24);
         simpleButton->setFont(font);
         connect(simpleButton,&QPushButton::clicked,[=](){
             this->close();
             gameRoom->setGeometry(this->geometry());
             gameRoom->show();
         });

     QPushButton* normalButton=new QPushButton(this);
     normalButton->move(440,340);
     normalButton->setText("一般模式");
     normalButton->setFont(font);
     connect( normalButton,&QPushButton::clicked,[=](){
         this->close();
         gameRoom->setGeometry(this->geometry());
         gameRoom->show();
     });

     QPushButton* hardButton=new QPushButton(this);
    hardButton->move(440,430);
     hardButton->setText("困难模式");
    hardButton->setFont(font); connect(hardButton,&QPushButton::clicked,[=](){
        this->close();
        gameRoom->setGeometry(this->geometry());
        gameRoom->show();
    });


     QPushButton* heistoryButton=new QPushButton(this);
     heistoryButton->move(440,520);
     heistoryButton->setText("历史战绩");
     heistoryButton->setFont(font);

     //先创建一个widget

         connect(heistoryButton,&QPushButton::clicked,[=]()
         {
         //在创建一个TextEdit
         QWidget* widget=new QWidget;
         widget->setWindowTitle("历史战绩");
         widget->setFixedSize(600,500);
         QTextEdit* textEdit=new QTextEdit(widget);

         textEdit->setFixedSize(widget->width(),widget->height());
         textEdit->setFont(font);
         textEdit->append("得分为：");
             //去文件里面读数据
         QFile file(":/score.txt");
         file.open(QIODevice::ReadOnly);
         QTextStream in(&file);
        int data=in.readLine().toInt();
         textEdit->append(QString::number(data));
         widget->show();
     });





}
//重写绘图事件
void gameSeleced::paintEvent(QPaintEvent *event)
{
    //实例化画家对象
    QPainter painter(this);
    //准备绘图设备
    QPixmap pixmap(":/gameseleced_background");
   painter.drawPixmap(0,0,this->width(),this->height(),pixmap);
     //画一个退出按钮，在右下角
}

